<script setup>
import { onMounted } from 'vue'
import RegisterDownload from '@/assets/images/register-download.png'

onMounted(() => {
  const sc = document.createElement('script');
  sc.type = 'text/javascript';
  sc.src = 'https://web.cdn.openinstall.io/openinstall.js';
  sc.addEventListener('load',()=>{
    console.log("load")
    const data = OpenInstall.parseUrlParams();//openinstall.js中提供的工具函数，解析url中的所有查询参数
    new OpenInstall({
      /*appKey必选参数，openinstall平台为每个应用分配的ID*/
      appKey : "nr5smh",
      /*可选参数，自定义android平台的apk下载文件名；个别andriod浏览器下载时，中文文件名显示乱码，请慎用中文文件名！*/
      apkFileName : 'jiaduobao.apk',
      /*可选参数，是否优先考虑拉起app，以牺牲下载体验为代价*/
      preferWakeup:true,
      /*自定义遮罩的html*/
      // mask:function(){
      //  return "<div id='openinstall_shadow' style='position:fixed;left:0;top:0;background:rgba(0,255,0,0.5);filter:alpha(opacity=50);width:100%;height:100%;z-index:10000;'></div>"
      // },
      /*openinstall初始化完成的回调函数，可选*/
      onready : function() {
        var m = this, button = document.getElementById("downloadButton");
        button.style.visibility = "visible";
        /*在app已安装的情况尝试拉起app*/
        m.schemeWakeup();
        /*用户点击某个按钮时(假定按钮id为downloadButton)，安装app*/
        button.onclick = function() {
          m.wakeupOrInstall();
          return false;
        }
      }
    }, data);
  },false)
  sc.addEventListener("error",(e)=>{
    console.log(e)
  })
  document.head.appendChild(sc);
})
</script>

<template>
  <div id="app">
    <div class="beijing" id="downloadButton" style="visibility: visible;">
      <img :src="RegisterDownload" style="width: 100%; height: 100%;" />
    </div>
  </div>
</template>

<style scoped>
</style>
